Skip to main content

1. Git Bash

什么是 Git Bash?

Git Bash 是 Windows 平台上的一个命令行工具,它提供了类似于 Unix 终端的环境,使用户能够使用 Git 及各种 Linux 命令。

info

Git Bash 是 Git for Windows 软件包的一部分,适用于 Windows 用户。

安装 Git Bash

  1. 访问 Git 官方网站 下载 Git。
  2. 按照安装向导完成安装,并选择 "Git Bash" 作为默认终端。
  3. 运行 git --version 以验证安装是否成功。

Git Bash 常见命令

1. 配置 Git

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
tip

使用 git config --list 查看所有当前配置。

2. 创建 Git 仓库

mkdir my-project
cd my-project
git init
caution

请确保 git init 只在需要 Git 版本控制的目录下执行,否则可能影响其他文件。

3. 提交代码

echo "Hello Git" > README.md
git add README.md
git commit -m "Initial commit"

4. 远程仓库操作

git remote add origin https://github.com/user/repo.git
git push -u origin main

Git Bash 使用示例

git clone https://github.com/user/repo.git
cd repo
git checkout -b feature-branch
git push origin feature-branch

进阶操作

Git 别名配置
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm "commit -m"

结论

Git Bash 提供了强大的 Git 版本控制支持,并且支持 Linux 命令。无论是初学者还是开发人员,都可以借助 Git Bash 高效管理项目。

更多 Git 资源